This program, given a source file, produces a document with syntax highlighting.
At the moment this package can handle
NOTICE: now the name of the program is source-highlight: there are no two separate programs, namely java2html and cpp2html, anymore. However there are two shell scripts with the same name in order to facilitate the migration (however their use is not advised).
GNU Source-highlight is free software. Please see the file COPYING for details. For documentation, please read this file.
GNU Source-highlight is a GNU program
and its main home page is at GNU site:
http://www.gnu.org/software/src-highlite/source-highlight.html
I do not distribute Windows binaries anymore; since, they can be easily
built by using Cygnus C/C++ compiler, available at http://www.cygwin.com/. However, if you
don't feel like downloading such compiler, you can request such binaries directly
to me, by e-mail (bettini@gnu.org) and
I can send them to you.
An MS-Windows port of Source-highlight is available from http://gnuwin32.sourceforge.net/.
You may also want to check the md5sum of the archives, which are also digitally signed by me (Lorenzo Bettini) with GNU gpg (http://www.gnupg.org). My GPG public key can be found at my home page (see at the end of this doc).
You can also get the patches, if they are available for a particular release (see below for patching from a previous version).
cvs -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/src-highlite login
cvs -z3 -d:pserver:anoncvs@subversions.gnu.org:/cvsroot/src-highlite co src-highliteFurther instructions can be found at the address: http://savannah.gnu.org/projects/src-highlite.
CGI support was enabled thanks to Robert Wetzel <rw8@mail.inf.tu-dresden.de>; I haven't tested it personally yet, so you may ask him directly. Moreover he set up some examples at the page http://www.inf.tu-dresden.de/~rw8/java2.html. If you want to use source-highlight as a CGI program, you have to use the executable source-highlight-cgi.
Moreover there's also a Java version of java2html, made by bayard@generationjava.com, you can find it at http://www.generationjava.com/java/Java2Html.shtml.
cd <source code main directory>Note: unless you specify a different install directory by --prefix option of configure (e.g. ./configure --prefix=<your home>), you must be root to 'make install'.
./configure
make
make install
It is also possible to specify as following option for configure: --enable-input-chroot to hardcode in the program the path to prefix for input files.
Before you run 'make install' you may want to check that the programs have compiled fine, so you can run 'make check'.
Files will be installed in the following directories:
source-highlight has been developed under Linux, using gcc (C++), and bison (yacc) and flex (lex), and ported under Win32 with Cygnus C/C++ compiler, available at http://www.cygwin.com/ (a .DLL is also distributed together with the .exe: you may simply copy it in the same place of the .exe). I used the excellent GNU Autoconf and Automake. I also used Autotools (ftp://ftp.ugcs.caltech.edu/pub/elef/autotools) which creates a starting source tree (according to GNU standards) with autoconf, automake starting files. Finally I used GNU gengetopt (http://www.gnu.org/software/gengetopt), for command line parsing.
Actually, unless you want to develop source-highlight, you don't need all these tools to build source-highlight because I provide generated sources; you don't need neither bison (yacc) nor flex (lex), for the same reason. Actually programs that use lex generated files need to link with library libfl (or libl for lex); anyway configuration phase can discover if this library is missing and in that case it sets the program to link with a source file I provide. This hack works for flex: I don't know about lex generated scanners. But, again, this is a problem only if you develop source-highlight and you use lex.
gunzip -cd ../source-highlight-1.3-1.3.1.patch.gz | patch -p1and restart the compilation process (if you had already run configure a simple make will do).
here's how to run source-highlight (for this example we will use C/C++ input files, but this is valid also for other source-highlight input languages):
source-highlight --src-lang cpp --out-format html --input <file (a C++ prog)> --output <file (an html)> [options]For input files, apart from the -i (--input) option and the standard input redirection, you can simply specify some files at the command line and also use regular expressions (for instance *.java). In this case the name for the output files will be formed using the name of the source file with a .<ext> appended, where <ext> is the extension chosen according to the output format specified (in this example it would be .html).
If STDOUT string is passed as -o (--output) option, then the output is forced to the standard output anyway.
Required command line options are:
Here are some links to some of the C and C++ sources of source-highlight colored with source-highlight itself:
startapp.cc.htmlgenerated with the following command
Obviously it works with C files as well:source-highlight -s cpp -f html --doc startapp.cc
cmdline.c.htmlCreated with the command (notice that this one uses both CSS file and headers and footers):
And obviously it works with header file as well:source-highlight -s cpp -f html -i cmdline.c -o cmdline.c.html
--css="cpp2html.css"
--header="./header.html" --footer="./footer.html"
cmdline.h.htmlcreated with the command:
Here are some examples of Java files processed with source-highlight: Use Hello.java to make some test, if you want. Here's how Hello1.html, Hello2.html, Hello3.html, Hello4.html, Hello5.html, Hello_h_f.html, Hello_lines.html, Hello_xhtml.html, Hello_xhtml2.html were created:source-highlight -s cpp -f html *.h --css="mono.css"
source-highlight -s java -f html -i Hello.java -o Hello1.htmlHere's the output of source-highlight applied to a Prolog program (through the option `source-highlight -s prolog`: test.pl.html. This one is an highlighted Perl program (through the option `source-highlight -s prolog`): test.pm.html. Here's an highlighted PHP3 program: test.php3.html. And here's a Python program: test.py.html. This the the flex scanner for flex files flex_scanner.ll.html.
source-highlight -s java -f html --input Hello.java --output Hello2.html --doc
source-highlight -s java -f html -i Hello.java -o Hello3.html --title "Happy Java with java2html :-)" --tab 3
source-highlight -s java -f html < Hello.java > Hello4.html --title "and what about CSS :-)" --css "Hello.css"
source-highlight -s java -f html < Hello.java > Hello5.html --title "Wooo... this is quite dark ;-D" --css "mono-alt.css"
source-highlight -s java -f html --doc *.java
Processed Hello.java (creates Hello.java.html)
source-highlight -s java -f html --doc -i Hello.java -o Hello_h_f.html --tags-file="tags2.j2h" --header="header.html" --footer="footer.html"
source-highlight -s java -f html --line-number --doc -i Hello.java -o Hello_lines.html
source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml.html --css xhtml.css
../src/source-highlight -s java -f xhtml --doc -i Hello.java -o Hello_xhtml2.html --tags-file tags.j2h
And here's the output of `source-highlight --help`
GNU source-highlight 1.6.1As it handles standard output and input you may also run it like
Purpose:
Highlight the syntax of a source file (e.g. Java)
into a specific format (e.g. HTML)
Usage: source-highlight [OPTIONS]... [FILES]...
-h --help Print help and exit
-V --version Print version and exit
-iSTRING --input=STRING input file. default std input
-oSTRING --output=STRING output file. default std output
-sSTRING --src-lang=STRING source language (e.g. java, cpp, prolog, perl, php3, python, flex, changelog)
-fSTRING --out-format=STRING output format (e.g. html, xhtml)
-v --verbose verbose mode on
-d --doc create html with title and header
-cSTRING --css=STRING use a css for formatting. Implies --doc
-TSTRING --title=STRING give a title to the html. Implies --doc
-tINT --tab=INT specify tab length. default 8
-HSTRING --header=STRING file to insert as header
-FSTRING --footer=STRING file to insert as footer
--tags-file=STRING specify format options (def. tags.j2h)
-n --line-number number all output lines
--output-dir=STRING output directory
Maintained by Lorenzo Bettini <bettini@gnu.org>
Report bugs to <bug-source-highlight@gnu.org>
cat MyFile.cpp | source-highlight -s cpp -f html | lprYou may want to specify your options for syntax highlighting in the file tags.j2h. If this file is not present in the current directory, some default colors will be used. Here's the tags.j2h file that comes with this distribution:
keyword blue b ; for language keywordstags2.j2h also specify the color of normal text, indeed it adds this line
type darkgreen ; for basic types
string red ; for strings and chars
comment brown i ; for comments
number purple ; for literal numbers
preproc darkblue b ; for preproc directives (e.g. #include, import)
symbol darkred ; for simbols (e.g. <, >, +)
function black b; for function calls and declarations
cbracket red; for block brackets (e.g. {, })
normal darkblue ;as you might see the syntax of this file is quite straightforward:
keyword blue u, b ;you may see all possible colors in the file colors.html but you can also use the standard #<number> html syntax for specifying a color.
if something goes wrong with your options try to run source-highlight with --verbose option enabled.
Actually I want to extend it, so if you have some ideas...
The most import one will be to make source-highlight more customizable :-)
Please send all bug reports by electronic mail to:
bug-source-highlight@gnu.org
My home page is http://www.lorenzobettini.it
source-highlight is free software. See the file COPYING for copying conditions. Anyway I won't get offended if you send me a postcard :-)
Return to GNU's home page.
Please send FSF & GNU inquiries & questions to gnu@gnu.org. There are also other ways to contact the FSF.
Please send comments on these web pages to webmasters@gnu.org, send other questions to gnu@gnu.org.
Copyright (C) 2001 Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA
Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.
Updated:9 Jan 2001 mhw